package net.alteiar.images.filter.elements;

import java.awt.Color;
import java.util.Observer;

import net.alteiar.images.filter.BasicFilter;
import net.alteiar.images.metadata.IImageInfo;
import net.alteiar.transformation.TransformationFunction;

public class BlockingFilter extends BasicFilter implements Observer {

	private static Color TRANSPARENT = new Color(0f, 0f, 0f, 0f);
	private static Color BLACK = new Color(0f, 0f, 0f, 0.8f);
	private static Color LIGHT = new Color(0.5f, 0.5f, 0f, 0.3f);

	private final TransformationFunction fct;

	public BlockingFilter(IImageInfo info) {
		super(info);

		// need to be really fast
		fct = new TransformationFunction() {
			@Override
			public int transform(int value) {
				int returnVal = TRANSPARENT.getRGB();
				if (value > 1) {
					returnVal = BLACK.getRGB();
				} else if (value < 1) {
					returnVal = LIGHT.getRGB();
				}
				return returnVal;
			}
		};

		info.addObserver(this);
		updateFilter();
	}

	@Override
	public void updateFilter() {
		int[] intImage = layer.getImagePixels();
		info.getValues(intImage, fct);
	}
}
